package com.design.movieticket.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.design.movieticket.entity.Role;
import com.design.movieticket.entity.Role;
import com.design.movieticket.mapper.RoleMapper;
import com.design.movieticket.mapper.RoleMapper;
import com.design.movieticket.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    /** 分页查询 */
    @Override
    public LambdaQueryWrapper buildQuery(Role role) {
        LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(Role.class)
                .eq(StringUtils.isNotBlank(role.getRoleName()),Role::getRoleName,role.getRoleName());
        return lambdaQueryWrapper;
    }

    /** 分页相关 */
    @Override
    public <E extends IPage<Role>> E page(E page, Wrapper<Role> queryWrapper) {
        return super.page(page, queryWrapper);
    }

    /** 新增或更新权限数据 */
    @Override
    public void addOrUpdateRoleInfo(Role role) {
        super.saveOrUpdate(role);
    }

    /** 获取权限信息详情 */
    @Override
    public Role getRoleDetail(long id) {
        return super.getById(id);
    }

    /** 删除权限信息 */
    @Override
    public void delRoleById(long id) {
        super.removeById(id);
    }
}
